<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>告警规则设置</title>
    <meta name="decorator" content="nblank"/>
    <%@include file="/WEB-INF/views/include/treetable.jsp" %>
    <link href="${ctxStatic}/modules/biz/record/equItemHisList.css" rel="stylesheet" itself="true" />
</head>
<body>
<div class="content container">
    <h2 class="page-title">告警规则设置
        <small>告警规则列表</small>
    </h2>
    <div class="row">
        <div class="col-md-12">
            <section class="widget widget-tabs">
                <header>
                    <ul class="nav nav-tabs">
                        <li id="eiwRuleList"><a href="${ctx}/biz/eiwRule?officeId=${officebiz.id}&sgroupId=${sgroup.id}">${officebiz.name}设备列表</a></li>
                        <li class="active"><a href="javascript:;">${officebiz.name}告警规则设置</a></li>
                    </ul>
                </header>
                <%--<sys:message content="${message}"/>--%>
                <div class="body tab-content">
                    <div class="tab-pane active clearfix" style="position: relative;">
                            <input type="hidden" id="inputOfficeId" value="${officebiz.id}" >
                            <input type="hidden" id="admin" value="${ctx}"/>
                            <input type="hidden" id="sgroupId" value="${sgroup.id}"/>

                            <div class="row pd-first2">
                                ${sgroup.name}&nbsp;${eitem.name}
                            </div>
                        <div class="widget mg-bottom">
                            <div class="list-box" id="inner-content-div">
                                <table id="mainTable" class="table table-striped  table-condensed tree_table overflow-auto">
                                    <thead>
                                    </thead>
                                    <tbody class="table-cor">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <div class="text-align-center">
                            <input id="btnCancel" class="btn btn-default" type="button"
                                   style="margin-left: -50px;min-width:100px;" value="返 回" onClick="$('#eiwRuleList a').trigger('click')"/>
                            <input id="manual" class="btn btn-primary" style="margin-left:50px;min-width:100px;"
                                   type="button" value="手动添加规则"/>&nbsp;
                            <input id="template" class="btn btn-primary" style="margin-left:50px;min-width:100px;"
                                   type="button" value="模板添加规则"/>&nbsp;
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<script type="text/javascript">
    var noData="暂无告警信息";
    var admin = $("#admin").val();
    var modify = "规则设置";
    var del = "删除";
    var officeId = $('#inputOfficeId').val();
    var sgroupId = $('#sgroupId').val();
    var itemId=${eitem.id};

    $(function () {
//        组查询的change事件
        var eiwRuleList = ${fns:toJson(eiwRuleList)};
        $("#mainTable thead").html("");
        $("#mainTable tbody").html("");
        if(eiwRuleList.length==0){
            $("<tr><td align='center'>" + noData + "</td></tr>").appendTo("#mainTable tbody");
        }else{
            $("#mainTable thead").append("<tr><th>参数</th><th>规则</th><th>时间段</th><th>等级</th><th>备注</th><th>操作</th></tr>");
            $.each(eiwRuleList,function (index, item) {
                var param="id="+item.id+"&officeId="+officeId+"&sgroupId="+sgroupId+"&itemId="+itemId;
                var tds="";
                tds+="<td>"+item.param.name+"</td>";
                tds+="<td>"+getDictLabel(${fns:toJson(fns:getDictList('comparison_operator'))}, item.comparisonOperator1);
                tds+="&nbsp;"+item.operand1;
                if(item.relationOperator!=''){
                    tds+="&nbsp;"+getDictLabel(${fns:toJson(fns:getDictList('relation_operator'))}, item.relationOperator);
                    tds+="&nbsp;"+getDictLabel(${fns:toJson(fns:getDictList('comparison_operator'))}, item.comparisonOperator2);
                    tds+="&nbsp;"+item.operand2;
                }
                tds+="</td>";
                tds+="<td>"+item.timeBegin+"&nbsp;--&nbsp;"+item.timeEnd+"</td>";
                tds+="<td>"+getDictLabel(${fns:toJson(fns:getDictList('event_level'))}, item.warnLevel)+"</td>";
                tds+="<td>"+item.remarks+"</td>";
                tds+="<td><a href='${ctx}/biz/eiwRule/form?"+param+"'>修改</a>";
                tds+="&nbsp;&nbsp;&nbsp;&nbsp;<a href='${ctx}/biz/eiwRule/delete?"+param+"' class='no-pjax' onclick=\"confirmx('确认删除该规则吗?',this.href);return false;\">删除</a></td>";
                $("<tr>"+tds+"</tr>").appendTo("#mainTable tbody");
            });
        }

        // 手动添加规则 按钮
        $('#manual').click(function () {
            location.href=admin+"/biz/eiwRule/form?officeId="+officeId+"&sgroupId="+sgroupId+"&itemId=${eitem.id}";
        });

        // 模板添加规则 按钮
        $('#template').click(function () {
            location.href=admin+"/biz/eiwRule/addThroughTemplateButton?officeId="+officeId+"&sgroupId="+sgroupId+"&itemId=${eitem.id}&dataLength="+eiwRuleList.length;
        });

    });
    /** jquery 部分结束 */

    /** 表单提交ajax部分 -- 开始 */
    function submitAjax(){
        $.ajax({
            type:"get",
            url:"${ctx}/biz/sgcfg/itemlist",
            data:{
                sgroupId:$('#sgroupId').val(),
            },
            dataType:"json",
            success: function (data) {
                $("#mainTable thead").html("");
                $("#mainTable tbody").html("");
                if (data != null) {
                    $("#mainTable thead").append("<tr><th>设备名称</th><th>规则设置</th></tr>");
                    $.each(data, function (indexColumn, item) {
                        $("<tr><td>" + item.gitem.name + "</td><td><a href='" + admin + "/biz/eiwRule/list?officeId="+officeId+"&sgroupId="+$('#sgroupId').val()+"&itemId=" + item.gitem.id + "'>" + modify + "</a>&nbsp;</td></tr>")
                                .appendTo("#mainTable tbody");
                    });
                } else {
                    $("<tr><td align='center'>" + noData + "</td></tr>").appendTo("#mainTable tbody");
                }
            }
        });
    }
    /** 表单提交ajax部分 -- 结束 */
</script>
</body>
</html>